import datetime as dt
import logging as log

#
# def log(something):
#     # if callable, this is a decorator, shape of @log
#     if callable(something):
#         func = something
#
#         @functools.wraps(func)
#         def wrapper(*args, **kwargs):
#             print('call {}'.format(func.__name__))
#             func(*args, **kwargs)
#
#         return wrapper
#
#     elif isinstance(something, str):
#         # else, this is a decorator function, shape of @log(something)
#         def decorator(func):
#             @functools.wraps(func)
#             def wrapper(*args, **kwargs):
#                 print('{} {}'.format(something, func.__name__))
#                 func(*args, **kwargs)
#
#             return wrapper
#
#         return decorator
#
#     else:
#         raise AttributeError("Attribute other than str is not supported")


def log(service_name):
    def decorator(func):
        def wrapper(*args, **kw):
            start_time = dt.datetime.now()

            print(u'call start %s(),备注：%s, 时间:%s' % (func.__name__, service_name, start_time))
            result = func(*args, **kw)
            end_time = dt.datetime.now()
            print(u'call end %s(),备注：%s, 时间:%s' % (func.__name__, service_name, end_time))
            return result

        return wrapper

    return decorator
